
#1、定义账号信息
accountlist = [{"卡号":'1',"密码":'1',"金额":12000},
               {"卡号":'2',"密码":'2',"金额":15000},
               {"卡号":'3',"密码":'3',"金额":18000},
               {"卡号":'4',"密码":'4',"金额":20000}]

#2、定义输出函数
def showmoney(accountlist):
    print("当前账户余额为：{}".format(accountlist["金额"]))

#a = showmoney([1])
#print("a",a)

#3、输出初始界面
print("="*8,"欢迎使用自助存取款系统","="*8)

#存入输入的卡号和密码
a1 = {}
a1["卡号"] = input("请输入卡号:")
a1["密码"] = input("请输入密码:")
#print("a1",a1)

#4、功能实现
for i in range(len(accountlist)):

    bs = 0

    #账号密码遍历
    a2 = {}
    a2["卡号"] = accountlist[i]["卡号"]
    a2["密码"] = accountlist[i]["密码"]
#    print("a2",a2)

    #比对卡号和密码
    if a2 == a1:
        
        while True:

            #页面展示
            print("="*8,"欢迎使用自助存取款系统","="*8)
            print("{0:1}{1:13}{2:15}".format(" ","1.查看余额","2.存钱"))
            print("{0:1}{1:15}{2:15}".format(" ","3.取款","4.退出"))
            print("="*40)
                    
            key = input("请选择操作：")

            if key =='1':
                print("="*6,"查看余额","="*6)
                                    
                showmoney(accountlist[i]) #显示余额
                                    
                print("回车键继续……")
            elif key == '2':
                print("="*8,"存钱","="*8)
                                    
                bmoney = int(accountlist[i]["金额"]) #余额
                
                smoney = int(input("存款金额：")) #存的金额
                accountlist[i]["金额"] = bmoney + smoney
                showmoney(accountlist[i]) #显示余额
                                
                print("回车键继续……")
            elif key == '3':
                print("="*8,"取款","="*8)

                bmoney = int(accountlist[i]["金额"])
                dmoney = int(input("取款金额："))

                if bmoney >= dmoney : #如果余额大于取款金额
                    accountlist[i]["金额"] = bmoney - dmoney
                    showmoney(accountlist[i]) #显示余额
                        
                    print("回车键继续……")
                else:
                    print("余额不足")
                    break
                    
                    
            elif key == '4':
                print("="*8,"再见","="*8)
                break            
            else: 
                print("="*8,"无效的输入","="*8)

    else:
        if  i == len(accountlist)-1 : #如果错误就退出
            print("="*5,"用户名或密码错误","="*5)
            break

        
            
    
